import { createStore, applyMiddleware, Middleware } from 'redux'
import persistReducer from "./reducers/rootReducer";
import thunk from 'redux-thunk';
import { persistStore } from 'redux-persist';
import logger from 'redux-logger';

// 中间件
const middlewares: Middleware[] = [thunk];
if (process.env.NODE_ENV === `development`) {
    // 开发环境使用
  middlewares.push(logger);
}

// 创建store
const store = applyMiddleware(...middlewares)(createStore)(persistReducer);

// store持久化
export const persistor = persistStore(store);

export default store;